home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_lib1 / rkrm_lib1.lha / Intuition / Intuition_GUI / easyintuition.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  9KB  |  236 lines

  1. ;/*
  2. lc -L -j73 easyintuition.c
  3. quit
  4. */
  5.  
  6. /*
  7. Copyright (c) 1992 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga, Inc. for
  10. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  11. published by Addison-Wesley (ISBN 0-201-56774-1).
  12.  
  13. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  14. information on the correct usage of the techniques and operating system
  15. functions presented in these examples.  The source and executable code
  16. of these examples may only be distributed in free electronic form, via
  17. bulletin board or as part of a fully non-commercial and freely
  18. redistributable diskette.  Both the source and executable code (including
  19. comments) must be included, without modification, in any copy.  This
  20. example may not be published in printed form or distributed with any
  21. commercial product.  However, the programming techniques and support
  22. routines set forth in these examples may be used in the development
  23. of original executable software products for Commodore Amiga computers.
  24.  
  25. All other rights reserved.
  26.  
  27. This example is provided "as-is" and is subject to change; no
  28. warranties are made.  All use is at your own risk. No liability or
  29. responsibility is assumed.
  30. */
  31.  
  32. /* easyintuition.c  Simple backward-compatible V37 Intuition example    */
  33. /*                                                                      */
  34. /* This example uses extended structures with the pre-V37 OpenScreen()  */
  35. /* and OpenWindow() functions to compatibly open an Intuition display.  */
  36. /* Enhanced V37 options specified via tags are ignored on 1.3 systems.  */
  37. /* Compiled with Lattice C v5.10: lc -L easyintuition.c                 */
  38.  
  39. /* Force use of new variable names to help prevent errors  */
  40. #define INTUI_V36_NAMES_ONLY
  41.  
  42. #include <exec/types.h>             /* The Amiga data types file.         */
  43. #include <intuition/intuition.h>    /* Intuition data strucutres, etc.    */
  44. #include <libraries/dos.h>          /* Official return codes defined here */
  45.  
  46. #include <clib/exec_protos.h>       /* Exec function prototypes           */
  47. #include <clib/intuition_protos.h>  /* Intuition function prototypes      */
  48.  
  49. #ifdef LATTICE                      /* Disable Ctrl-C handling in SAS/C   */
  50. int CXBRK(void)  {return(0);}
  51. void chkabort(void) {return;}
  52. #endif
  53.  
  54. /* Use lowest non-obsolete version that supplies the functions needed. */
  55. #define INTUITION_REV 33L
  56.  
  57. /* Declare the prototypes of our own functions. Prototypes for system  */
  58. /* functions are declared in the header files in the clib directory    */
  59. VOID cleanExit( struct Screen *, struct Window *, LONG );
  60. BOOL handleIDCMP( struct Window *);
  61.  
  62. struct Library *IntuitionBase = NULL;
  63.  
  64. /* We can specify that we want the V37-compatible 3D look when
  65.  * running under V37 by adding an SA_Pens tag.
  66.  */
  67. WORD pens[] = {~0};     /* empty pen array to get default 3D look */
  68. struct TagItem ourscreentags[] = {
  69.         { SA_Pens, (ULONG)pens },
  70.         { TAG_DONE }};
  71.  
  72. /* ExtNewScreen is an extended NewScreen structure.
  73.  * NS_EXTENDED flags that there is a tag pointer to additional
  74.  * tag information at the end of this structure.  The tags will
  75.  * be parsed by Release 2 but ignored by earlier OS versions.
  76.  */
  77. struct ExtNewScreen fullHires =
  78.     {
  79.     0,                /* LeftEdge must be zero prior to Release 2 */
  80.     0,                /* TopEdge */
  81.     640,              /* Width (high-resolution) */
  82.     STDSCREENHEIGHT,  /* Height (non-interlace)  */
  83.     2,                /* Depth (4 colors will be available) */
  84.     0,1,              /* Default DetailPen and BlockPen  */
  85.     HIRES,            /* the high-resolution display mode */
  86.     CUSTOMSCREEN | NS_EXTENDED,     /* the screen type */
  87.     NULL,             /* no special font */
  88.     "Our Screen",     /* the screen title */
  89.     NULL,             /* no custom screen gadgets (not supported) */
  90.     NULL,             /* no CustomBitMap */
  91.     ourscreentags     /* tags for additional V37 features */
  92.     };
  93.  
  94. /* Position and sizes for our window */
  95. #define WIN_LEFTEDGE   20
  96. #define WIN_TOPEDGE    20
  97. #define WIN_WIDTH     400
  98. #define WIN_MINWIDTH   80
  99. #define WIN_HEIGHT    150
  100. #define WIN_MINHEIGHT  20
  101.  
  102. /* Under V37, we'll get a special screen title when our window is active */
  103. UBYTE activetitle[] = {"Our Screen - EasyWindow is Active"};
  104.  
  105. struct TagItem ourwindowtags[] = {
  106.         { WA_ScreenTitle, (ULONG)&activetitle[0] },
  107.         { TAG_DONE }};
  108.  
  109. /* ExtNewWindow is an extended NewWindow structure.
  110.  * NW_EXTENDED indicates that there is a tag pointer to additional tag
  111.  * information at the end of this structure.  The tags will be parsed
  112.  * by Release 2 but ignored by earlier OS versions.
  113.  */
  114. struct ExtNewWindow easyWindow =
  115.     {
  116.     WIN_LEFTEDGE,
  117.     WIN_TOPEDGE,
  118.     WIN_WIDTH,
  119.     WIN_HEIGHT,
  120.     -1,-1,             /* Means use the screen's Detail and Block pens   */
  121.  
  122.     IDCMP_CLOSEWINDOW, /* This field specifies the events we want to get */
  123.  
  124.     /* These flags specify system gadgets and other window attributes    */
  125.     /* including the EXTENDED flag which flags this as an ExtNewWindow   */
  126.     WFLG_CLOSEGADGET | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_DRAGBAR |
  127.     WFLG_DEPTHGADGET | WFLG_SIZEGADGET  | WFLG_NOCAREREFRESH |
  128.     WFLG_NW_EXTENDED,
  129.  
  130.     NULL,             /* Pointer to the first gadget  */
  131.     NULL,             /* No checkmark.                */
  132.     "EasyWindow",     /* Window title.                */
  133.     NULL,             /* Attach a screen later.       */
  134.     NULL,             /* Let Intuition set up BitMap  */
  135.     WIN_MINWIDTH,     /* Minimum width.       */
  136.     WIN_MINHEIGHT,    /* Minimum height.      */
  137.     -1,               /* Maximum width (screen size)  */
  138.     -1,               /* Maximum height (screen size) */
  139.     CUSTOMSCREEN,     /* A screen of our own. */
  140.     ourwindowtags     /* tags for additional V37 features */
  141.     };
  142.  
  143.  
  144. VOID main(int argc, char *argv[])
  145. {
  146.     /* Declare variables here */
  147.     ULONG signalmask, winsignal, signals;
  148.     BOOL done = FALSE;
  149.     struct Screen *screen1 = NULL;
  150.     struct Window *window1 = NULL;
  151.  
  152.     /* Open Intuition Library.  NOTE - We are accepting version 33 (1.2)
  153.      * or higher because we are opening our display in a compatible manner.
  154.      * However - If you add to this example, do NOT use any NEW V37
  155.      * functions unless IntuitionBase->lib_Version is >= 37
  156.      */
  157.     IntuitionBase = OpenLibrary( "intuition.library",INTUITION_REV );
  158.     if (IntuitionBase == NULL)
  159.         cleanExit(screen1, window1, RETURN_WARN);
  160.  
  161.     /* Open any other required libraries and make */
  162.     /* any assignments that were postponed above  */
  163.  
  164.     /* Open the screen */
  165.     screen1 = OpenScreen(&fullHires);
  166.     if (screen1 == NULL)
  167.         cleanExit(screen1, window1, RETURN_WARN);
  168.  
  169.     /* Attach the window to the open screen ... */
  170.     easyWindow.Screen = screen1;
  171.  
  172.     /* ... and open the window */
  173.     window1 = OpenWindow(&easyWindow);
  174.     if (window1 == NULL)
  175.         cleanExit(screen1, window1, RETURN_WARN);
  176.  
  177.     /* Set up the signals for the events we want to hear about ...   */
  178.     winsignal = 1L << window1->UserPort->mp_SigBit;  /* window IDCMP */
  179.     signalmask = winsignal;     /* we will only wait on IDCMP events */
  180.  
  181.     /* Here's the main input event loop where we wait for events.    */
  182.     /* We have asked Intuition to send us CLOSEWINDOW IDCMP events   */
  183.     /* Exec will wake us if any event we are waiting for occurs.     */
  184.     while( !done )
  185.     {
  186.         signals = Wait(signalmask);
  187.  
  188.         /* An event occurred - now act on the signal(s) we received.*/
  189.         /* We were only waiting on one signal (winsignal) in our    */
  190.         /* signalmask, so we actually know we received winsignal.   */
  191.         if(signals & winsignal)
  192.             done = handleIDCMP(window1);    /* done if close gadget */
  193.     }
  194.     cleanExit(screen1, window1, RETURN_OK); /* Exit the program     */
  195. }
  196.  
  197.  
  198. BOOL handleIDCMP( struct Window *win )
  199. {
  200.     BOOL done = FALSE;
  201.     struct IntuiMessage *message;
  202.     ULONG class;
  203.  
  204.     /* Examine pending messages */
  205.     while( message = (struct IntuiMessage *)GetMsg(win->UserPort) )
  206.     {
  207.         class = message->Class;   /* get all data we need from message */
  208.  
  209.         /* When we're through with a message, reply */
  210.         ReplyMsg( (struct Message *)message);
  211.  
  212.         /* See what events occurred */
  213.         switch( class )
  214.         {
  215.             case IDCMP_CLOSEWINDOW:
  216.                 done = TRUE;
  217.                 break;
  218.             default:
  219.                 break;
  220.         }
  221.     }
  222.     return(done);
  223. }
  224.  
  225.  
  226. VOID cleanExit( struct Screen *scrn, struct Window *wind, LONG returnValue )
  227. {
  228.     /* Close things in the reverse order of opening */
  229.     if (wind) CloseWindow( wind );      /* Close window if opened */
  230.     if (scrn) CloseScreen( scrn );      /* Close screen if opened */
  231.  
  232.     /* Close the library, and then exit */
  233.     if (IntuitionBase) CloseLibrary( IntuitionBase );
  234.     exit(returnValue);
  235. }
  236.